/**
 * Created with hong.rong
 * Description:私有路由
 * Date:2020/06/24
 */

import React, { useEffect } from 'react'
import { connect, Redirect } from 'umi'

const PrivateRoute = ({ children, dispatch }) => {
  const token = localStorage.getItem('token')
  /**
   * constructor
   */
  useEffect(() => {
    // if (dispatch && token) {
    //   dispatch({
    //     type: 'global/fetchCurrent',
    //   })
    // }
  }, [])

  if (!token) {
    return <Redirect to="/login" />
  }

  return children
}

export default connect(({ global }) => ({
  global,
}))(PrivateRoute)
